package cn.ainit.butn.proceduce;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.ainit.common.ReturnObject;
import cn.ainit.common.cwReturnObject;
import cn.ainit.sys.menu.SessionCont;

/****
 * 点击按钮事件
 * @author xuzq
 *
 */
@Controller
@RequestMapping("/butpro")
public class ButnProController {
	
	ButnProService butnProService;
	
	@Resource
	public void setButnProService(ButnProService butnProService) {
		this.butnProService = butnProService;
	}
	
	/***
	 * 执行按钮的存储过程(或许批量)
	 * @param buParams
	 * @param request
	 * @param session
	 * @return
	 * @author Xuzq
	 * @date 2014-4-24 下午04:55:21
	 */
	@RequestMapping("/buts")
	@ResponseBody
	public ReturnObject execPro(@RequestBody ButScripParams buParams, HttpServletRequest request,HttpSession session){
		ReturnObject returnObject = new ReturnObject();
		try {
			//设置用户信息
			Object uid = session.getAttribute(SessionCont.uid);
			Object staid = session.getAttribute(SessionCont.STATION_ID);
			buParams.setUid(uid == null?"":uid.toString());
			buParams.setStaid(staid == null?"":staid.toString());
			//处理dsid
			String[] tmpStr = buParams.getDsid().split(";");
			buParams.setDsid(tmpStr[0]);
			returnObject = butnProService.execPro(buParams);
			
		} catch (Exception e) {
			e.printStackTrace();
			returnObject.setMsg("error");
			returnObject.setInfo(e.getMessage());
		}

		return returnObject;
	}
	
	/***
	 * 执行按钮的存储过程
	 * @param buParams
	 * @param request
	 * @param session
	 * @return
	 * @author Xuzq
	 * @date 2014-4-24 下午04:55:21
	 */
	@RequestMapping("/butsPro")
	@ResponseBody
	public ReturnObject execProButn(@RequestBody ButScripParams buParams, HttpServletRequest request,HttpSession session){
		ReturnObject returnObject = new ReturnObject();
		try {
			//设置用户信息
			Object uid = session.getAttribute(SessionCont.uid); //manId
			Object staid = session.getAttribute(SessionCont.STATION_ID); //stationId
			buParams.setUid(uid == null?"":uid.toString());
			buParams.setStaid(staid == null?"":staid.toString());
			//处理dsid 
			String[] tmpStr = buParams.getDsid().split(";");  //dsId
			buParams.setDsid(tmpStr[0]);
			returnObject = butnProService.execButnPro(buParams); //执行存储过程
		} catch (Exception e) {
			e.printStackTrace();
//			returnObject.setMsg("error");
//			returnObject.setInfo(e.getMessage());
		}

		return returnObject;
	}
	
	/***
	 * 执行按钮的存储过程（操作选中的行）
	 * @param buParams
	 * @param request
	 * @param session
	 * @return
	 * @author Xuzq
	 * @date 2014-4-24 下午04:55:21
	 */
	@RequestMapping("/butproSel")
	@ResponseBody
	public ReturnObject butproSel(@RequestBody ButScripParams buParams, HttpServletRequest request,HttpSession session){
		ReturnObject returnObject = new ReturnObject();
		try {
			//设置用户信息
			Object uid = session.getAttribute(SessionCont.uid); //manId
			Object staid = session.getAttribute(SessionCont.STATION_ID); //stationId
			buParams.setUid(uid == null?"":uid.toString());
			buParams.setStaid(staid == null?"":staid.toString());
			//处理dsid 
			String[] tmpStr = buParams.getDsid().split(";");  //dsId
			buParams.setDsid(tmpStr[0]);
			returnObject=butnProService.butproSel(buParams);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return returnObject;
	}
	
	
	
	
	
	/***
	 * 批量审核
	 * @param buParams
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping("/butsPLVerify")
	@ResponseBody
	public ReturnObject execProPLS(@RequestBody ButScripParams buParams, HttpServletRequest request,HttpSession session){
		ReturnObject returnObject = new ReturnObject();
		try {
			//设置用户信息
			Object uid = session.getAttribute(SessionCont.uid);
			Object staid = session.getAttribute(SessionCont.STATION_ID);
			buParams.setUid(uid == null?"":uid.toString());
			buParams.setStaid(staid == null?"":staid.toString());
			returnObject = butnProService.execButnProPLV(buParams);
		} catch (Exception e) {
			e.printStackTrace();
//			returnObject.setMsg("error");
//			returnObject.setInfo(e.getMessage());
		}
		return returnObject;
	}
	
	
	/***
	 * 财务：报销单和综合费用单的批量审核
	 * @param buParams
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping("/cwPlVerifyButn")
	@ResponseBody
	public cwReturnObject execCwPlVerify(@RequestBody ButScripParams buParams, HttpServletRequest request,HttpSession session){
		cwReturnObject cwReturnObject= new cwReturnObject();
		try {
			//设置用户信息
			Object uid = session.getAttribute(SessionCont.uid);
			Object staid = session.getAttribute(SessionCont.STATION_ID);
			buParams.setUid(uid == null?"":uid.toString());
			buParams.setStaid(staid == null?"":staid.toString());
			cwReturnObject= butnProService.cwPlVerifyButn(buParams);
		} catch (Exception e) {
			e.printStackTrace();
//			returnObject.setMsg("error");
//			returnObject.setInfo(e.getMessage());
		}
		return cwReturnObject;
	}
	
	/***
	 * 财务：报销单和综合费用单的批量审核
	 * @param buParams
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping("/cwPlFUKUANButn")
	@ResponseBody
	public cwReturnObject execCwPlFUKUAN(@RequestBody ButScripParams buParams, HttpServletRequest request,HttpSession session){
		cwReturnObject cwReturnObject= new cwReturnObject();
		try {
			//设置用户信息
			Object uid = session.getAttribute(SessionCont.uid);
			Object staid = session.getAttribute(SessionCont.STATION_ID);
			buParams.setUid(uid == null?"":uid.toString());
			buParams.setStaid(staid == null?"":staid.toString());
			cwReturnObject= butnProService.execCwPlFUKUAN(buParams);
		} catch (Exception e) {
			e.printStackTrace();
//			returnObject.setMsg("error");
//			returnObject.setInfo(e.getMessage());
		}
		return cwReturnObject;
	}
	
	/***
	 * 批量入库
	 * @param buParams
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping("/butsPLInStock")
	@ResponseBody
	public ReturnObject execProInStock(@RequestBody ButScripParams buParams, HttpServletRequest request,HttpSession session){
		ReturnObject returnObject = new ReturnObject();
		try {
			//设置用户信息
			Object uid = session.getAttribute(SessionCont.uid);
			Object staid = session.getAttribute(SessionCont.STATION_ID);
			buParams.setUid(uid == null?"":uid.toString());
			buParams.setStaid(staid == null?"":staid.toString());
			returnObject = butnProService.execButnProPLInStock(buParams);
		} catch (Exception e) {
			e.printStackTrace();
//			returnObject.setMsg("error");
//			returnObject.setInfo(e.getMessage());
		}

		return returnObject;
	}
	
	
	/***
	 * 批量出库
	 * @param buParams
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping("/butsPLOutStock")
	@ResponseBody
	public ReturnObject execProOutStock(@RequestBody ButScripParams buParams, HttpServletRequest request,HttpSession session){
		ReturnObject returnObject = new ReturnObject();
		try {
			//设置用户信息
			Object uid = session.getAttribute(SessionCont.uid);
			Object staid = session.getAttribute(SessionCont.STATION_ID);
			buParams.setUid(uid == null?"":uid.toString());
			buParams.setStaid(staid == null?"":staid.toString());
			returnObject = butnProService.execButnProPLOutStock(buParams);
		} catch (Exception e) {
			e.printStackTrace();
//			returnObject.setMsg("error");
//			returnObject.setInfo(e.getMessage());
		}

		return returnObject;
	}
	
	
	

	/***
	 * 转U8操作  执行 按钮
	 * @return dsId   buParams
	 * 传入前台的所有ID 
	 */
	@RequestMapping("/zhuanHZ")
	@ResponseBody
	public ReturnObject zhuanHZ(@RequestBody ButScripParams buParams,HttpServletRequest request,HttpSession session){
		ReturnObject returnObject = new ReturnObject();
		try {
			String uid = (String) (session.getAttribute(SessionCont.uid)==null?"":session.getAttribute(SessionCont.uid));
			returnObject = butnProService.zhuanHZ(buParams,uid);//dsid 和 行记录
		} catch (Exception e) {
			e.printStackTrace();
		}
		return returnObject;
	}

    /***
     * 财务：应付费用单的批量审核
     * @param buParams
     * @param request
     * @param session
     * @return
     */
    @RequestMapping("/cwCSSPlVerifyButn")
    @ResponseBody
    public cwReturnObject cwCSSPlVerifyButn(@RequestBody ButScripParams buParams, HttpServletRequest request,HttpSession session){
        cwReturnObject cwReturnObject= new cwReturnObject();
        try {
            //设置用户信息
            Object uid = session.getAttribute(SessionCont.uid);
            Object staid = session.getAttribute(SessionCont.STATION_ID);
            buParams.setUid(uid == null?"":uid.toString());
            buParams.setStaid(staid == null?"":staid.toString());
            cwReturnObject= butnProService.cwCSSPlVerifyButn(buParams);
        } catch (Exception e) {
            e.printStackTrace();
//			returnObject.setMsg("error");
//			returnObject.setInfo(e.getMessage());
        }
        return cwReturnObject;
    }
	
	
}
